package com.zy.openchat.core.model.file;

import android.annotation.SuppressLint;
import android.os.Parcel;
import android.os.Parcelable;

import com.zy.openchat.core.manager.TelegramManager;

public class FileTaskInfo implements Parcelable {
    //头像时，对应userid
    public String id;
    public long file_id;
    public TelegramManager.FileType fileType;
    public long timestamp;

    public int priority() {
        switch (fileType) {
            case FileType_Photo:
                return 32;
            case FileType_Group_Photo:
                return 32;
            case FileType_Message_Photo:
                return 32;
            case FileType_Message_Preview_Photo:
                return 32;
            case FileType_Message_Video:
                return 32;
            case FileType_Message_Audio:
                return 32;
            case FileType_Message_Voice:
                return 32;
            case FileType_Message_Document:
                return 32;
            case FileType_Message_Animation:
                return 32;
            default:
                return 0;
        }
    }

    public String fileTaskKey() {
        return fileTaskKey(fileType, file_id);
    }

    @SuppressLint("DefaultLocale")
    public static String fileTaskKey(TelegramManager.FileType type, long file_id) {
        switch (type) {
            case FileType_Photo:
                return String.format("photo_%d", file_id);
            case FileType_Group_Photo:
                return String.format("group_photo_%d", file_id);
            case FileType_Message_Photo:
                return String.format("message_photo_%d", file_id);
            case FileType_Message_Preview_Photo:
                return String.format("message_preview_photo_%d", file_id);
            case FileType_Message_Video:
                return String.format("message_video_%d", file_id);
            case FileType_Message_Audio:
                return String.format("message_audio_%d", file_id);
            case FileType_Message_Voice:
                return String.format("message_voice_%d", file_id);
            case FileType_Message_Document:
                return String.format("message_document_%d", file_id);
            case FileType_Message_Animation:
                return String.format("animation_%d", file_id);
            default:
                return "";
        }
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.id);
        dest.writeLong(this.file_id);
        dest.writeInt(this.fileType == null ? -1 : this.fileType.ordinal());
    }

    public FileTaskInfo() {
    }

    protected FileTaskInfo(Parcel in) {
        this.id = in.readString();
        this.file_id = in.readLong();
        int tmpFileType = in.readInt();
        this.fileType = tmpFileType == -1 ? null : TelegramManager.FileType.values()[tmpFileType];
    }

    public static final Creator<FileTaskInfo> CREATOR = new Creator<FileTaskInfo>() {
        @Override
        public FileTaskInfo createFromParcel(Parcel source) {
            return new FileTaskInfo(source);
        }

        @Override
        public FileTaskInfo[] newArray(int size) {
            return new FileTaskInfo[size];
        }
    };
}
